const Koa  = require('koa')
const Router = require('@koa/router');
var cors = require('koa2-cors');
 


const app  = new Koa()
const router = new Router();

//跨域
app.use(cors());

let data = [{task:'playying',date:'20220512'},{task:'eatting',date:'20220512'},{task:'sleeping',date:'20220512'}]

const taskConstroller  = async (ctx, next) => {
  //获取数据

  //响应数据
  ctx.body = data
}

router.get('/tasks', taskConstroller);
  
app
.use(router.routes())
.use(router.allowedMethods());


app.listen(3001,(err)=>{
    if(err){
        console.log(err);
    }
    console.log('server is running on 3001');
})